package indi.zhifa.engine.test.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import indi.zhifa.core.common.web.entity.ann.ZhiFaRestController;
import indi.zhifa.core.common.web.entity.response.RestResponse;
import indi.zhifa.engine.test.busylogic.test.entity.TestEntityDto;
import indi.zhifa.engine.test.busylogic.test.service.ITestCurdService;
import indi.zhifa.engine.test.gen.busy.item.entity.GenItemDefineEntity;
import indi.zhifa.engine.test.gen.busy.item.mapper.GenItemDefineMapper;
import indi.zhifa.engine.test.gen.busy.item.service.IGenItemDefineDbService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Validated
@RequiredArgsConstructor
@RequestMapping(value = "/api/zhifa-engine/test/crud")
@ZhiFaRestController
@Tag(name = "CRUD测试接口")
public class CrudController {

    private final ITestCurdService mTestCurdService;
    private final IGenItemDefineDbService mItemDefineDbService;

    @PostMapping("/mpEnhance/testEntity")
    public RestResponse<String> mpSave(@RequestBody TestEntityDto pTestDto){
        mTestCurdService.mpSave(pTestDto);
        return RestResponse.ok("插入成功") ;
    }

    @Operation(summary = "商品page")
    @GetMapping("/item/page")
    public Page<GenItemDefineEntity> page(@RequestParam(name = "size") Integer pSize,
                                          @RequestParam(name = "current") Integer pCurrent){
        Page<GenItemDefineEntity> page = new Page<>(pCurrent, pSize);
        Page<GenItemDefineEntity> res = mItemDefineDbService.page(page, Wrappers.<GenItemDefineEntity>lambdaQuery());
        return res;
    }

}
